package com.xdkj.es.controller;

import com.xdkj.es.service.JDGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author joke
 * @version 1.0
 * @date 2021/12/19-15:12
 */
@RestController
@RequestMapping("es")
public class EsController {

    @Autowired
    JDGoodsService jdgoodsService;

    @GetMapping("findAll")
    public Object findAll() {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 2000);
        map.put("message", "success");
        map.put("data", Arrays.asList("Hello", "World", "java", "C++"));
        return map;
    }

    @GetMapping("/search/{keyword}/{pageNo}/{pageSize}")
    public List<Map<String, Object>> keywordSearch(@PathVariable("keyword") String keyword,
                                                   @PathVariable Integer pageNo,
                                                   @PathVariable int pageSize) throws Exception {
        return jdgoodsService.searchPage(keyword, pageNo, pageSize);
    }

}
